package com.koala.learn.json;

import com.alibaba.fastjson.JSON;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.junit.Test;

import java.io.IOException;

/**
 * @author yantingrui
 * @date 2022/7/18   13:43
 */
public class Start {

    private static final String str = " {\n" +
            "            \"name\": \"中国光大银行(洪山支行)\",\n" +
            "            \"id\": \"B001B09TPM\",\n" +
            "            \"location\": \"114.353216,30.527406\",\n" +
            "            \"type\": \"金融保险服务;银行;中国光大银行\",\n" +
            "            \"typecode\": \"160113\",\n" +
            "            \"pname\": \"湖北省\",\n" +
            "            \"cityname\": \"武汉市\",\n" +
            "            \"adname\": \"洪山区\",\n" +
            "            \"address\": \"武珞路745号(街道口地铁站D口步行160米)\",\n" +
            "            \"pcode\": \"420000\",\n" +
            "            \"citycode\": \"027\",\n" +
            "            \"adcode\": \"420111\",\n" +
            "            \"business\": {\n" +
            "                \"business_area\": \"珞南\",\n" +
            "                \"tel\": \"027-87869755;027-87860755\",\n" +
            "                \"rectag\": \"营业厅\",\n" +
            "                \"keytag\": \"营业厅\",\n" +
            "                \"alias\": \"光大银行(洪山支行)\",\n" +
            "                \"opentime_today\": \"08:30-17:00\",\n" +
            "                \"opentime_week\": \"08:30-17:00\"\n" +
            "            }\n" +
            "        }";

    public static void main(String[] args) {

        Pois parse = JSON.parseObject(str, Pois.class);
        System.out.println(parse.toString());
    }


    @Test
    public void test43() throws IOException {
        Role role = new Role("1222", 1);
        ObjectMapper mapper = new ObjectMapper();
        String s = mapper.writeValueAsString(role);
        System.out.println(s);
        Role role1 = mapper.readValue(s, Role.class);


    }

    /**
     *
     */
    @Test
    public void test62() {
        String s = "{\"page\":1,\"size\":10,\"visitTime\":[\"2022-08-10 00:00:00\",\"2022-09-29 23:59:59\"]}";
        System.out.println(JSON.parseObject(s));
    }

    /**
     * 看能不能得到内部的
     */
    @Test
    public void test63() throws IOException {

        ObjectMapper mapper = new ObjectMapper();
        JsonNode jsonNode = mapper.readTree(str);
        JsonNode distance = jsonNode.findValue("distance");
        System.out.println(distance);
    }
}
